public class TestAnimal {
    public static Animal buyAnimal(String var){
        if ("狗".equals(var)){
            return new Dog("大黄",2);
        }else if ("猫".equals(var)){
            return new Cat("云宝",3);
        }else{
            return null;
        }
    }

    public static void main(String[] args) {

        Animal animal = buyAnimal("狗");
        Animal animal2 = buyAnimal("猫");

        animal.eat();
        animal2.eat();


    }
}
